package com.ruoyi.peizhen.service.impl;

import java.util.List;
import java.util.ArrayList;
import com.ruoyi.common.core.domain.Ztree;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.peizhen.mapper.HospitalDepartmentMapper;
import com.ruoyi.peizhen.domain.HospitalDepartment;
import com.ruoyi.peizhen.service.IHospitalDepartmentService;
import com.ruoyi.common.core.text.Convert;

/**
 * 科室Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-03-13
 */
@Service
public class HospitalDepartmentServiceImpl implements IHospitalDepartmentService 
{
    @Autowired
    private HospitalDepartmentMapper hospitalDepartmentMapper;

    /**
     * 查询科室
     * 
     * @param id 科室主键
     * @return 科室
     */
    @Override
    public HospitalDepartment selectHospitalDepartmentById(Long id)
    {
        return hospitalDepartmentMapper.selectHospitalDepartmentById(id);
    }

    /**
     * 查询科室列表
     * 
     * @param hospitalDepartment 科室
     * @return 科室
     */
    @Override
    public List<HospitalDepartment> selectHospitalDepartmentList(HospitalDepartment hospitalDepartment)
    {
        return hospitalDepartmentMapper.selectHospitalDepartmentList(hospitalDepartment);
    }

    /**
     * 新增科室
     * 
     * @param hospitalDepartment 科室
     * @return 结果
     */
    @Override
    public int insertHospitalDepartment(HospitalDepartment hospitalDepartment)
    {
        hospitalDepartment.setCreateTime(DateUtils.getNowDate());
        return hospitalDepartmentMapper.insertHospitalDepartment(hospitalDepartment);
    }

    /**
     * 修改科室
     * 
     * @param hospitalDepartment 科室
     * @return 结果
     */
    @Override
    public int updateHospitalDepartment(HospitalDepartment hospitalDepartment)
    {
        hospitalDepartment.setUpdateTime(DateUtils.getNowDate());
        return hospitalDepartmentMapper.updateHospitalDepartment(hospitalDepartment);
    }

    /**
     * 批量删除科室
     * 
     * @param ids 需要删除的科室主键
     * @return 结果
     */
    @Override
    public int deleteHospitalDepartmentByIds(String ids)
    {
        return hospitalDepartmentMapper.deleteHospitalDepartmentByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除科室信息
     * 
     * @param id 科室主键
     * @return 结果
     */
    @Override
    public int deleteHospitalDepartmentById(Long id)
    {
        return hospitalDepartmentMapper.deleteHospitalDepartmentById(id);
    }

    /**
     * 查询科室树列表
     * 
     * @return 所有科室信息
     */
    @Override
    public List<Ztree> selectHospitalDepartmentTree()
    {
        List<HospitalDepartment> hospitalDepartmentList = hospitalDepartmentMapper.selectHospitalDepartmentList(new HospitalDepartment());
        List<Ztree> ztrees = new ArrayList<Ztree>();
        for (HospitalDepartment hospitalDepartment : hospitalDepartmentList)
        {
            Ztree ztree = new Ztree();
            ztree.setId(hospitalDepartment.getDepartmentFatherId());
            ztree.setpId(hospitalDepartment.getId());
            ztree.setName(hospitalDepartment.getDepartmentName());
            ztree.setTitle(hospitalDepartment.getDepartmentName());
            ztrees.add(ztree);
        }
        return ztrees;
    }
}
